package com.bins.dentist.clinic.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bins.dentist.clinic.model.dto.DeptDto;
import com.bins.dentist.clinic.model.dto.DeptPageDto;
import com.bins.dentist.clinic.model.vo.DeptVo;
import com.bins.dentist.clinic.model.vo.ResultVo;
import com.bins.dentist.clinic.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bins
 * @since 2023-02-20 20:53:30
 */
@RestController
@RequestMapping("/system/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping("/page")
    public ResultVo<IPage<DeptVo>> pageList(DeptPageDto pageDto) {
        IPage<DeptVo> pageInfo = deptService.getPage(pageDto);
        ResultVo<IPage<DeptVo>> result = new ResultVo<IPage<DeptVo>>();
        result.setData(pageInfo);
        return result;
    }

    @GetMapping("/detail")
    public ResultVo<DeptVo> detail(DeptDto dto) {
        return ResultVo.ok().data(deptService.getDetailById(dto));
    }

    @PostMapping("/save")
    public ResultVo<DeptVo> saveDept(@RequestBody DeptDto dto) {
        return ResultVo.ok().data(deptService.saveDept(dto));
    }

    @PostMapping("/delete")
    public ResultVo<Integer> deleteDept(@RequestBody DeptDto dto){
        return ResultVo.ok().data(deptService.deleteDept(dto));
    }

}

